<?php
    require('00_init.php');
    // family_id
    @$family_id=$_REQUEST["family_id"];
    if(!preg_match("/^[0-9]+$/",$family_id)){
      die('{"code":-1,"msg":"验证类别family_id错误"}');
    }
    //   title 标题
      @$title=$_REQUEST["title"];
    if(!preg_match("/\S+/",$title)){
          die('{"code":-1,"msg":"验证类别title错误"}');
       }
    //   subtitle 副标题
       @$subtitle=$_REQUEST["subtitle"];
         if(!preg_match("/\S+/",$subtitle)){
              die('{"code":-1,"msg":"验证类别subtitle错误"}');
           }
    //   price 价格
     @$price=$_REQUEST["price"];
         if(!preg_match("/\d{1,}.\d{2}/",$price)){
              die('{"code":-1,"msg":"验证类别price错误"}');
           }
    //   promise 服务承诺
         @$promise=$_REQUEST["promise"];
         if(!preg_match("/\S+/",$promise)){
              die('{"code":-1,"msg":"验证类别promise错误"}');
           }
    //   spec 规格颜色
      @$spec=$_REQUEST["spec"];
         if(!preg_match("/\S+/",$spec)){
              die('{"code":-1,"msg":"验证类别spec错误"}');
           }
    //   name 商品名称
     @$name=$_REQUEST["name"];
        if(!preg_match("/\S+/",$name)){
              die('{"code":-1,"msg":"验证类别name错误"}');
           }
    //   os 操作系统
      @$os=$_REQUEST["os"];
         if(!preg_match("/\S+/",$os)){
              die('{"code":-1,"msg":"验证类别os错误"}');
           }
    //   memory 内存容量
      @$memory=$_REQUEST["memory"];
       if(!preg_match("/^[\d]+[a-zA-Z]+$/",$memory)){
                die('{"code":-1,"msg":"验证类别memory错误"}');
       }
    //   resolution 分辨率
     @$resolution=$_REQUEST["resolution"];
      if(!preg_match("/^[\d]+\*[\d]+$/",$resolution)){

             die('{"code":-1,"msg":"验证类别resolution错误"}');
     }
    //   $video_card 显卡型号
     @$video_card=$_REQUEST["video_card"];
      if(!preg_match("/\S+/",$video_card)){
              die('{"code":-1,"msg":"验证类别video_card错误"}');
         }
    //   $cpu 处理器
       @$cpu=$_REQUEST["cpu"];
    if(!preg_match("/\S+/",$cpu)){
                 die('{"code":-1,"msg":"验证类别cpu错误"}');
        }
    //   $video_memory 显存内容
          @$video_memory=$_REQUEST["video_memory"];
        if(!preg_match("/\S+/",$video_memory)){
                 die('{"code":-1,"msg":"验证类别video_memory错误"}');
        }
    //   $category  所属分类
          @$category=$_REQUEST["category"];
            if(!preg_match("/\S+/",$category)){
                       die('{"code":-1,"msg":"验证类别category错误"}');
              }
    //   $disk  硬盘容量及类型
          @$disk=$_REQUEST["disk"];
           if(!preg_match("/\S+/",$disk)){
                     die('{"code":-1,"msg":"验证类别disk错误"}');
            }
    //   $details 产品详细说明
          @$details=$_REQUEST["details"];
            if(!preg_match("/\S+/",$details)){
                       die('{"code":-1,"msg":"验证类别details错误"}');
              }
    //   $sold_count 销售数量
          @$sold_count=$_REQUEST["sold_count"];
    //   $is_onsale 是否促销
          @$is_onsale=$_REQUEST["is_onsale"];
           if(!preg_match("/^[0-1]{1}$/",$is_onsale)){
                                 die('{"code":-1,"msg":"验证类别is_onsale错误"}');
                        }
    //   $expire 是否删除
          @$expire=0;
    //   $cuid
        @$cuid=$_REQUEST['cuid'];
           if(!preg_match("/^[0-9]+$/",$cuid)){
                                         die('{"code":-1,"msg":"验证类别cuid错误"}');
                                }
    //   $ctime
    //   $muid 默认
    //   $mtime 默认
    //   $v1 默认
    //   $v2 默认
    //   $vi3 默认
    //   $vi4 默认
       $sql="INSERT INTO xz_laptop VALUES(";
        $sql.="null,$family_id,'$title',";
        $sql.="'$subtitle',$price,'$promise',";
        $sql.="'$spec','$name','$os','$memory',";
        $sql.="'$resolution','$video_card','$cpu',";
        $sql.="'$video_memory','$category','$disk',";
        $sql.="'$details',unix_timestamp(),0,$is_onsale,";
        $sql.="'0',$cuid,now(),0,0,";
        $sql.="'','',0,0";
       $sql.=")";
       $result=mysqli_query($conn,$sql);
       if($result){
            if(mysqli_affected_rows($conn)){
                echo '{"code":0,"msg":"添加成功"}';
            }else{
             echo '{"code":-1,"msg":"添加失败"}';
            }
       }else{
        echo $sql;
       }

       /*
       http://localhost/XueZiShangCheng/data/09_product_add.php?family_id=123&title=大师&subtitle=大师2&price=200.00&promise=一年包换&spec=红色&name=宝宝&os=苹果系统&memory=2G&resolution=2000*1800&video_card=集成显卡&cpu=Intel%20i5低功耗版&video_memory=其它&category=轻薄本&disk=128G固态&details=asdasdsadsafsa&is_onsale=1&cuid=1
       */
?>
